<template>
  <div>
    <!-- 对话框(添加 / 修改) -->
    <el-dialog
      :title="title"
      :visible.sync="show"
      width="80%"
      append-to-body
      :before-close="cancel"
      :close-on-click-modal="false"
    >
      <el-row>
        <div class="group-name">基本信息</div>
        <el-col class="item" :span="8"
          >所属学院:{{ calssDetail.collegeName }}</el-col
        >
        <el-col class="item" :span="8"
          >所属系部:{{ calssDetail.departmentsName }}</el-col
        >
        <el-col class="item" :span="8"
          >所属年级:{{ calssDetail.classesGrade }}</el-col
        >
        <el-col class="item" :span="8"
          >所属专业:{{ calssDetail.professionsName }}</el-col
        >
        <el-col class="item" :span="8"
          >班级编号:{{ calssDetail.classesNumber }}</el-col
        >
        <el-col class="item" :span="8"
          >班级名称:{{ calssDetail.classesName }}</el-col
        >
        <el-col class="item" :span="8"
          >开班时间:{{
            parseTime(calssDetail.openingTime, "{y}-{m}-{d}")
          }}</el-col
        >
        <el-col class="item" :span="8"
          >在班学生:{{ calssDetail.studentCount }}人</el-col
        >
        <el-col
          class="item"
          :span="8"
          v-for="(item, index) in calssDetail.classesTeacherDTOS"
          :key="index"
          >{{
            item.teacherUserType == 1
              ? "班主任"
              : item.teacherUserType == 2
              ? "辅导员"
              : "教师"
          }}:{{ item.teacherUserName }}</el-col
        >
        <el-col class="item" :span="8"
          >班级介绍:{{ calssDetail.classesIntroduce }}</el-col
        >
      </el-row>
      <div class="line"></div>
      <el-table v-loading="loading" :data="list">
        <el-table-column label="编号" align="center" prop="serialNumber" />
        <el-table-column label="学号" align="center" prop="studentNumber" />
        <el-table-column label="法号" align="center" prop="legalName" />
        <el-table-column label="姓名" align="center" prop="studentName" />
        <el-table-column label="性别" align="center" prop="studentSex">
          <template slot-scope="scope">
            <dict-tag
              :type="DICT_TYPE.SYSTEM_USER_SEX"
              :value="scope.row.studentSex"
            />
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="studentAge" />
        <el-table-column label="学院" align="center" prop="college" />
        <el-table-column label="专业" align="center" prop="professionName" />
        <el-table-column label="入学时间" align="center" prop="enrollmentTime">
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.enrollmentTime, "{y}-{m}-{d}")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="在籍状态" align="center" prop="recordStatus" />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
              >评价</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>

    <!-- 评价组件 -->
    <evaluation-edit
      :show.sync="openEvaluation"
      v-if="openEvaluation"
      :title="openEvaluationTitle"
      :studentId="studentId"
    ></evaluation-edit>
  </div>
</template>

<script>
import { getClasses, getClassesStudentPage } from "@/api/teacherSide/classes";
import evaluationEdit from "./evaluationEdit";
export default {
  name: "ClassesEdit",
  components: {
    evaluationEdit
  },
  data() {
    return {
      calssDetail: {},
      loading: true,
      list: [],
      total: 0,
      queryParams: {
        pageNo: 1,
        pageSize: 10,
      },
      studentId: undefined,
      openEvaluation: false,
      openEvaluationTitle: ""
    };
  },
  created() {
    this.getData();
    this.getList();
  },
  props: {
    // 班级id
    classId: {
      type: String,
      default: "",
    },

    show: {
      type: Boolean,
      default: false,
    },
    // 显示弹出层标题
    title: {
      type: String,
      default: "",
    },
  },
  watch: {
    classId(val) {
      this.getData();
      this.getList();
    },
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getClassesStudentPage({ ...this.queryParams, id: this.classId }).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    getData() {
      getClasses(this.classId).then((res) => {
        this.calssDetail = res.data;
      });
    },
    cancel() {
      this.$emit("update:show", false);
    },

    /**
     * 打开评价窗口
     * @param row
     */
    handleUpdate(row) {
      this.studentId = row.id;
      this.openEvaluation = true;
      this.openEvaluationTitle = "评价";

    },
  },
};
</script>
<style scoped>
.item {
  margin: 10px 0;
}
.line {
  border: 2px solid #999999;
  margin: 10px 0;
}
</style>
